//package com.freejava.test_spring_security.config;
//
//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
//
///**
// * Security配置类
// */
//@EnableWebSecurity
//public class SecurityConfig extends WebSecurityConfigurerAdapter {
//
//    /**
//     * 认证
//     * @param auth
//     * @throws Exception
//     */
//    @Override
//    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
//        auth.inMemoryAuthentication()
//                .passwordEncoder(new BCryptPasswordEncoder())
//                .withUser("freejava")
//                .password(new BCryptPasswordEncoder().encode("1234567"))
//                .roles("VIP1");
//
//    }
//    /**
//     * 授权
//     * @param http
//     * @throws Exception
//     */
//    @Override
//    protected void configure(HttpSecurity http) throws Exception {
//        // 设置匹配的资源白名单访问
//        http.authorizeRequests().antMatchers("/","/asserts/**","/pages/login.html","/userlogin")
//                .permitAll()
//                .antMatchers("/level1/**").hasRole("VIP1")
//                .antMatchers("/level2/**").hasRole("VIP2")
//                .antMatchers("/level3/**").hasRole("VIP3")
//                .anyRequest().authenticated();//剩余任何资源必须认证
//        // 开启登录页
//        http.formLogin();
//        // 开启自动注销
//        http.logout().logoutSuccessUrl("/login");// 注销之后来到登录页
//        http.csrf().disable();
//    }
//}
